import {
  login as _login,
  getUserInfo as _getUserInfo,
  wxLogin as _wxLogin,
  logout as _logout,
  getWxCode,
} from '@/api/login'
import { repPositionList } from '@/api/representative'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { toast, showToastAsync } from '@/utils/toast'
import { ITenantInfoVo, IUserLogin } from '@/api/login.typings'
import bgGH3 from '@/static/bgGH3.jpg'

export const useTenantStore = defineStore(
  'tenant',
  () => {
    // 定义用户信息
    const tenantInfo = ref<Partial<ITenantInfoVo>>({})
    const setTenant = (info: ITenantInfoVo) => {
      tenantInfo.value = info
      uni.setStorageSync('TENANT_INFO', info)
    }
    const loadFromStorage = () => {
      const info = uni.getStorageSync('TENANT_INFO')
      if (info) tenantInfo.value = info
    }
    const clearTenant = () => {
      tenantInfo.value = null
      uni.removeStorageSync('TENANT_INFO')
    }

    return {
      tenantInfo,
      setTenant,
      loadFromStorage,
      clearTenant,
    }
  },
  {
    persist: true,
  },
)
